
#include <stdio.h>
#include <unistd.h>
#include <linux/getprocinfo.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>

#include "print_task.h"


int main() {


  printf("\nThis program will print out the state of a process.");
  
  printf("\nA running task: state should be 0");
  printf("\nHere is my task_info_struct information: ");
  struct proc_info_struct s;
  getprocinfo( 0, &s );
  print_task( &s );

  
  printf("\nForking a child and then sending it a stop signal.\n");
  int pid = fork();
  if ( pid ) {
    printf("\nStopping child (%d)", pid);
    // Send child a stop signal
    kill( pid, SIGTSTP );
    sleep(1);
    printf("\nPrinting the child's info struct. State should be >0 : \n");
    struct proc_info_struct c;
    getprocinfo( pid, &c );
    print_task( &c );
    
    printf("\n\nContinuing the child.\n");
    kill( pid, SIGCONT );
    
    printf("\nWaiting for child to finish.\n");
    sleep(10);
    
    printf("\nPrinting the child's info struct. State should be >0\n");
    getprocinfo( pid, &c );
    print_task( &c );
    
    waitpid( pid, NULL, 0 );

  }
  else {

    sleep(5);
    exit(0);

  }


  return 0;

}
